# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=poco
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.10.1
pkgrel=2
pkgdesc="POrtable COmponents C++ Libraries (mingw-w64)"
arch=('any')
url="https://pocoproject.org/"
license=("boost")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-pkg-config")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-expat"
         "${MINGW_PACKAGE_PREFIX}-libmariadbclient"
         "${MINGW_PACKAGE_PREFIX}-openssl"
         "${MINGW_PACKAGE_PREFIX}-pcre"
         "${MINGW_PACKAGE_PREFIX}-sqlite3"
         "${MINGW_PACKAGE_PREFIX}-zlib")
options=('staticlibs' 'strip')
source=(https://pocoproject.org/releases/${_realname}-${pkgver}/${_realname}-${pkgver}-all.tar.gz
        004-format-string-using-ostringstream.patch
        005-dont-compare-signed-unsigned.patch
        007-mingw-wide-character-startup-module.patch
        008-Add-Mingw32-W64-configuration.patch
        010-remove-warnings.patch
        011-cmake-mingw.patch
        012-fix-mingw-redefinition.patch
        100-fix-mingw-config.patch)
sha256sums=('7f5931e0bb06bc2880a0f3867053a2fddf6c0d3e5dd96342a665460301fc34ca'
            '35d59c5880f82b154ca850e6a9c9627aa34a497ccc2fb1c8f93bea2616b15e2d'
            'ac05804b1c90d682333cb18dbc4aedc9e12508779e93edbd59d9b82d353b0013'
            '8c89571920fb5d0ecaae1b890854335fb5d310243baa4723233fe46544cf4f1b'
            '61979c75b5577b9b0bf3fb96045b3c299a38c5dfc5048895ade73400831eb975'
            '6428620c4e24f4b1d7a81821e46b737a9dfc2ce7cfd4d57187243fb12f17a7ce'
            '028889a3bcd9a7886153e9ffc7058a8e91654f6dc4a821b6d53deb3dc9870318'
            'ea527ad21e3cf31140136a037add87610cd8cdbcdd96ba2aaf5d7b35d46786ce'
            'c12fc09a0fa925bf3912fbc98e297104f09630212fd027b818290df7ef157a6f')

prepare() {
  cd "${srcdir}"/${_realname}-${pkgver}-all
  patch -p1 -i ${srcdir}/004-format-string-using-ostringstream.patch
  patch -p1 -i ${srcdir}/005-dont-compare-signed-unsigned.patch
  patch -p1 -i ${srcdir}/007-mingw-wide-character-startup-module.patch
  patch -p1 -i ${srcdir}/008-Add-Mingw32-W64-configuration.patch
  patch -p1 -i ${srcdir}/010-remove-warnings.patch
  patch -p1 -i ${srcdir}/011-cmake-mingw.patch
  patch -p1 -i ${srcdir}/012-fix-mingw-redefinition.patch
  patch -p1 -i ${srcdir}/100-fix-mingw-config.patch
}

build() {
  local _config=
  case "${CARCH}" in
    i686)
      _config=MinGW
    ;;

    x86_64)
      _config=MinGW32-W64
    ;;
  esac

  CXXFLAGS+=" -std=c++11"
  [[ -d ${srcdir}/build-${MINGW_CHOST} ]] && rm -rf ${srcdir}/build-${MINGW_CHOST}
  mkdir -p "${srcdir}/build-${MINGW_CHOST}" && cd "${srcdir}/build-${MINGW_CHOST}"

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DCMAKE_BUILD_TYPE=Release \
    -DPOCO_UNBUNDLED=ON \
    -DENABLE_MONGODB=OFF \
    ../${_realname}-${pkgver}-all

  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make destdir=${pkgdir} install
}
